package day_2022_7_to_8.day48;

import java.util.LinkedList;
import java.util.List;

/**
 * 组合总和 III
 * @author haomin
 * @date 2022/07/18 12:38
 **/
public class Day4_2_Num216_CombinationSum3 {
    public List<List<Integer>> result = new LinkedList<>();
    public List<Integer> ret = new LinkedList<>();

    public List<List<Integer>> combinationSum3(int k, int n) {
        dfs(0, 0, k, n);
        return result;
    }
    public void dfs(int start,int sum,int k,int n){
        if(ret.size() == k && sum == n){
            result.add(new LinkedList<>(ret));
        }
        for(int i = start;i < 10;i++){
            sum+=i;ret.add(i);
            dfs(i+1,sum,k,n);
            sum-=i;ret.remove(ret.size()-1);
        }
    }
}